package com.css.fxfzaqbz.modules.assessplot.controller;

import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.assessplot.service.HouseSeismicService;
import com.css.fxfzaqbz.modules.assessplot.vo.HouseSeismicByYPGVO;
import com.css.fxfzaqbz.modules.assessplot.vo.HouseSeismicVo;
import com.css.fxfzaqbz.modules.assessplot.vo.PlotVo;
import com.css.fxfzaqbz.modules.base.entity.SeismicResult;
import com.css.fxfzaqbz.modules.supergraph.exception.CustomException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 房屋地震灾害风险评估
 */
@RestController
@RequestMapping("/assessplot/houseSeismic")
@Slf4j
public class HouseSeismicController {

    @Resource
    private HouseSeismicService houseSeismicService;

    //  抗震能力算法 评估
    @PostMapping("/countSeismic")
    public RestResponse countSeismic(@RequestBody HouseSeismicVo vo) {
        RestResponse restResponse = null;
        try{
            List<SeismicResult> seismicResults = houseSeismicService.countSeismic(vo);
            restResponse = RestResponse.succeed(seismicResults);
        }catch (CustomException e) {
            log.error(e.getMessage());
            restResponse = RestResponse.fail(e.getMessage());
        } catch (Exception e){
            log.error("评估失败",e);
            restResponse = RestResponse.fail("评估失败!");
        }
        return restResponse;
    }
    //  抗震能力算法 评估
    @PostMapping("/countSeismicByYPG")
    public RestResponse countSeismicByYPG(@RequestBody HouseSeismicByYPGVO vo) {
        RestResponse restResponse = null;
        try{
            restResponse =houseSeismicService.countSeismicByYPG(vo);
        }catch (CustomException e) {
            log.error(e.getMessage());
            restResponse = RestResponse.fail(e.getMessage());
        } catch (Exception e){
            log.error("评估失败",e);
            restResponse = RestResponse.fail("评估失败!");
        }
        return restResponse;
    }

    //房屋破坏算法 评估
    @PostMapping("/houseDestory")
    public RestResponse houseDestory(@RequestBody HouseSeismicVo vo) {
        RestResponse restResponse = null;
        try{
            String uuid = houseSeismicService.houseDestory(vo);
            restResponse = RestResponse.succeed(uuid);
        }catch (CustomException e) {
            log.error(e.getMessage());
            restResponse = RestResponse.fail(e.getMessage());
        } catch (Exception e){
            log.error("评估失败",e);
            restResponse = RestResponse.fail("评估失败!");
        }
        return restResponse;
    }

    //  抗震能力出图
    @PostMapping("/seismicPlot")
    public RestResponse seismicPlot(@RequestBody PlotVo vo) {
        RestResponse restResponse = null;
        try{
            Map<String, Object> responseMap = houseSeismicService.seismicPlot(vo);
            restResponse = RestResponse.succeed(responseMap);
        }catch (CustomException e) {
            log.error(e.getMessage());
            restResponse = RestResponse.fail(e.getMessage());
        } catch (Exception e){
            log.error("出图失败",e);
            restResponse = RestResponse.fail("出图失败!");
        }
        return restResponse;
    }

    //  房屋破坏出图
    @PostMapping("/housePlot")
    public RestResponse housePlot(@RequestBody PlotVo vo) {
        RestResponse restResponse = null;
        try{
            Map<String, Object> responseMap = houseSeismicService.housePlot(vo);
            restResponse = RestResponse.succeed(responseMap);
        }catch (CustomException e) {
            log.error(e.getMessage());
            restResponse = RestResponse.fail(e.getMessage());
        } catch (Exception e){
            log.error("出图失败",e);
            restResponse = RestResponse.fail("出图失败!");
        }
        return restResponse;
    }
}
